#!/bin/bash

# 激活conda环境
source /home/wwilliamss/anaconda3/etc/profile.d/conda.sh
conda init
conda activate work

# 获取当前是星期几（1-7，其中1代表星期一）
day_of_week=$(date +%u)

# 如果是周一(1)、周三(3)或周五(5)，则执行补货建议生成
if [ "$day_of_week" -eq 1 ] || [ "$day_of_week" -eq 3 ] || [ "$day_of_week" -eq 5 ]; then
    echo "今天是需要执行补货建议生成的日子" >> /home/wwilliamss/retail-simulator/replenishment.log
    python manage.py replenishment_product >> /home/wwilliamss/retail-simulator/replenishment.log 2>&1
    
    # 检查补货建议生成是否成功
    if [ $? -eq 0 ]; then
        echo "补货建议生成成功，继续执行库存更新" >> /home/wwilliamss/retail-simulator/replenishment.log
    else
        echo "补货建议生成失败，但仍继续执行库存更新" >> /home/wwilliamss/retail-simulator/replenishment.log
    fi
fi

# 无论补货建议是否执行，每天都执行库存更新
python manage.py storage_product >> /home/wwilliamss/retail-simulator/storage.log 2>&1

# 执行库存快照
python manage.py product_snapshot >> /home/wwilliamss/retail-simulator/snapshot.log 2>&1
if [ $? -eq 0 ]; then
    echo "库存快照生成成功" >> /home/wwilliamss/retail-simulator/snapshot.log
else
    echo "库存快照生成失败" >> /home/wwilliamss/retail-simulator/snapshot.log
fi
